﻿@{
    Layout = null;
    int z = 0;
}
@model EnterpriseFund.Model.UpLevelAllowance
<!DOCTYPE html>
@Html.Partial("LoadPanelPartial")
<html>
<head>
    <title>UpLevelAllowanceEdit</title>
    @if (false)
    {
        <script src="../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery-ui.css", true)" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/json2.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.min.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/regex.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>
    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)
    <script>
        $(document).ready(function () {
            $("#toolMenu").smartFloat();
            var hdjsAlert = $("#hdjsAlert").val();
            if (hdjsAlert != "") {
                alert(hdjsAlert);
            }
            if (hdjsAlert == "操作成功") {
                window.location.href = rootPath + '/UpLevelAllowance/';
            }
        });

        function delADD(code) {
            var je = $("#" + code + "je").text();
            var jeSUM = $("#jeSUM").text();
            $("#jeSUM").text((jeSUM - je).toFixed(2));
            $("tr[id='" + code + "']").remove();
        }
        function refresh() {
            // 
            var no = document.getElementsByName("hidNSRDZDAH");
            var psrt = "";
            for (var i = 0; i < no.length; i++) {
                if (i != (no.length - 1)) {
                    psrt += no[i].value + ",";

                }
                else {
                    psrt += no[i].value;
                }

            }

            //    psrt = psrt.TrimEnd(',');
            // alert("1");
            //  window.location.reload();
            $.ajax({
                type: 'POST',
                url: rootPath + '/UpLevelAllowance/GetAdddata',
                data: { pdata: psrt },
                success: function (result) {
                    // alert("1");
                    if (result.split('|')[0] == "error") {
                        alert(result.split('|')[1]);
                    }
                    else {
                        // 
                        var pjson = JSON.parse(result);
                        for (var i = 0; i < pjson.length; i++) {
                            ok(pjson[i].NSRMC, pjson[i].NSRDZDAH, pjson[i].FLocalAmount, pjson[i].FUpLevelAmount, pjson[i].FNote);


                            // return "true";
                        }
                        codeModalMode.Hide();
                        alert("导入成功！");
                    }
                }
            });

        }
        //编码保存取消
        function codeCancel() {
            codeModalMode.Hide();
        }

        function codeAdd() {
            $("#popContent").attr("src", rootPath + "/UpLevelAllowance/TaxPayerAdd");
            codeModalMode.Show();
        }

        function MenuTop_emClick(source, e) {
            switch (e.item.name) {
                case "btnSubmit":
                    {
                        Save();
                        break;
                    }
                case "btnAdd":
                    {
                        codeAdd();
                        break;
                    }
                case "btnback":
                    {
                        window.location.href = rootPath + '/UpLevelAllowance/';
                        break;
                    }
                case "btnImport":
                    {
                        Import();
                        break;
                    }
            }

        }
        function Import() {
            // showWindow(rootUrl + 'YGZAllowanceImport');
            $("#popContent").attr("src", rootPath + "/UpLevelAllowance/Import");
            codeModalMode.Show();
        }
        function ok(NSRMC, NSRDZDAH, FLocalAmount, FUpLevelAmount, FNote) {
            if ($("#hidNSRDZDAH").val() != "undefined" && $("#hidNSRDZDAH").val() != undefined) {

                var no = document.getElementsByName("hidNSRDZDAH");
                // var list = no.split(',');
                for (var i = 0; i < no.length; i++) {
                    if (no[i].value == NSRDZDAH) {
                        alert(NSRMC + "该纳税户已存在，请核对后继续操作");

                        return;
                    }
                }

            }
            if (Number(FLocalAmount) == 0) {
                FLocalAmount = 0;
            }
            if (Number(FUpLevelAmount) == 0) {
                FUpLevelAmount = 0;
            }
            //        var FLocalAmount = Number(FLocalAmount).toFixed(2);
            //        if (FLocalAmount == null) {
            //            alert("请输入正确的地方配套金额");
            //        }
            //        var FUpLevelAmount = Number(FUpLevelAmount).toFixed(2);
            //        if (FUpLevelAmount == null) {
            //            alert("请输入正确的补助金额");
            //        }

            $("tr[id='sumR']").before("<tr id='" + NSRDZDAH + "'> <input type='hidden' name='hid" + NSRDZDAH + "FLocalAmount'  id='hid" + NSRDZDAH + "FLocalAmount' value='" + FLocalAmount + "'/> <input type='hidden'  name='hid" + NSRDZDAH + "FUpLevelAmount'  id='hid" + NSRDZDAH + "FUpLevelAmount' value='" + FUpLevelAmount + "'/> <input type='hidden' name='hid" + NSRDZDAH + "FNote'  id='hid" + NSRDZDAH + "FNote' value='" + FNote + "'/> <input type='hidden'  id='hidNSRDZDAH'  name='hidNSRDZDAH' value='" + NSRDZDAH + "'/><td class='tdClass' align='center'><a href='#' onclick=\"delADD('" + NSRDZDAH + "')\">删除</a></td> <td class='tdClass' align='left'>" + NSRMC + "</td> <td class='tdClass' align='right' id='" + NSRDZDAH + "je'>" + (Number(FUpLevelAmount) + Number(FLocalAmount)).toFixed(2) + "</td> <td class='tdClass' align='center'>" + FNote + "</td></tr>");
            var jeSUM = $("#jeSUM").text();
            $("#jeSUM").text((Number(jeSUM) + Number(FLocalAmount) + Number(FUpLevelAmount)).toFixed(2));
            codeModalMode.Hide();
        }

        function Save() {
            var errmsg = "";
            if (FFileNo.GetText() == "") {
                errmsg += "文件号,";
            }
            if (FFileName.GetText() == "") {
                errmsg += "文件名称,";
            }
            if (FUpLevelAllowanceClsNo.GetText() == "") {
                errmsg += "其他补助类型,";
            }
            if (FFinancePropNo.GetText() == "") {
                errmsg += "经济类型,";
            }
            if (errmsg == "") {
                form1.submit();
            }
            else {
                errmsg += "不能为空请确认后提交"
                alert(errmsg);
            }
        }
    </script>
    <style>
        .tableStyle
        {
            width: 100%;
            border: solid 1px black;
            padding: 6px 5px;
            border-collapse: collapse;
        }
        .tableStyle td
        {
        }
        
        .tableStyle .tdClass
        {
            padding: 0px;
            padding: 6px 5px;
            border: solid 1px black;
        }
        .tableStyle th
        {
            text-align: right;
            padding: 6px 5px;
            border: solid 1px black;
        }
        .tableStyle .button
        {
            margin: 2px 0px 0px 2px;
            float: left;
        }
        
        text
        {
            border: 1px solid #aecaf0;
        }
    </style>
</head>
<body>
    @using (Html.BeginForm("Save", "UpLevelAllowance", FormMethod.Post, new { id = "form1" }))
    {
        @Html.DevExpress().Menu(settings =>
{
    settings.Name = "toolBarMenu";
    settings.ItemAutoWidth = false;
    settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
    settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
    settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
    settings.Items.Add(item =>
    {
        item.Name = "btnSubmit";
        item.Text = "发送";
        item.Image.Url = Url.Content("~/Content/ControlImages/edit_add.png");
    });
    settings.Items.Add(item =>
    {
        item.Name = "btnAdd";
        item.Text = "补助录入";
        item.Image.Url = Url.Content("~/Content/ControlImages/sh.png");
    });
    settings.Items.Add(item =>
    {
        item.Name = "btnImport";
        item.Text = "excel导入";
        item.Image.Url = Url.Content("~/Content/ControlImages/excel.png");
    });
    settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
    settings.ItemLinkMode = ItemLinkMode.ContentBounds;
    settings.Items.Add(item =>
    {
        item.Name = "btnback";
        item.Text = "返回";
        item.Image.Url = Url.Content("~/Content/ControlImages/back.png");
    });
    settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
    settings.ItemLinkMode = ItemLinkMode.ContentBounds;
}).GetHtml()
        <div>
            <table width="100%">
                <tr>
                    <td align="right">
                        文号:
                    </td>
                    <td style="width: 150px">
                        @Html.DevExpress().TextBox(settings =>
                {
                    settings.Name = "FFileNo";
                    settings.Width = System.Web.UI.WebControls.Unit.Pixel(300);
                    settings.Text = Model.FFileNo;

                }).GetHtml()
                    </td>
                    <td align="right">
                        文件名称:
                    </td>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                {
                    settings.Name = "FFileName";
                    settings.Width = 300;
                    settings.Text = Model.FFileName;

                }).GetHtml()
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        其他补助类型:
                    </td>
                    <td>
                        @Html.DevExpress().ComboBox(settings =>
               {
                   settings.Name = "FUpLevelAllowanceClsNo";
                   settings.Properties.DropDownStyle = DropDownStyle.DropDownList;
                   settings.Width = 300;
                   settings.Properties.TextField = "FUpLevelAllowanceClsName";
                   settings.Properties.ValueField = "FUpLevelAllowanceClsNo";
               }).BindList(ViewData["UpLevelAllowanceClsList"]).Bind(Model.FUpLevelAllowanceClsNo).GetHtml()
                    </td>
                    <td style="width: 10%" align="right">
                        资金性质:
                    </td>
                    <td>
                        @Html.DevExpress().ComboBox(settings =>
               {
                   settings.Name = "FFinancePropNo";
                   settings.Properties.DropDownStyle = DropDownStyle.DropDownList;
                   settings.Width = 300;
                   settings.Properties.TextField = "FFinancePropShortName";
                   settings.Properties.ValueField = "FFinancePropNo";
                   settings.Properties.EnableClientSideAPI = true;
               }).BindList(ViewData["FinancePropList"]).Bind(Model.FFinancePropNo).GetHtml()
                    </td>
                </tr>
            </table>
            <table class="tableStyle">
                <tr>
                    <td class="tdClass" style="width: 10%" align="center">
                        操作
                    </td>
                    <td class="tdClass" style="width: 40%" align="center">
                        纳税人名称
                    </td>
                    <td class="tdClass" style="width: 15%" align="center">
                        金额(元)
                    </td>
                    <td class="tdClass" style="width: 45%" align="center">
                        备注
                    </td>
                </tr>
                @if (ViewData["showdata"] != null)
                {

                    foreach (System.Data.DataRow dr in (ViewData["showdata"] as System.Data.DataTable).Rows)
                    {
                        z++;
                        if (dr["cz"] == "mx")
                        {
                    <tr id="@dr["NSRDZDAH"]">
                        @Html.Hidden("hidNSRDZDAH", dr["NSRDZDAH"])
                        <td class="tdClass" align="center">
                            <a href="#" onclick="delADD('@dr["NSRDZDAH"]')">删除</a>
                        </td>
                        <td class="tdClass" align="left">@dr["NSRMC"]
                        </td>
                        @{
                            string amountcount = (decimal.Parse(dr["FLocalAmount"].ToString()) + decimal.Parse(dr["FUpLevelAmount"].ToString())).ToString();
                            <td class="tdClass" align="right" id='@dr["NSRDZDAH"]je'>
                                @amountcount
                            </td>
                            
                            }
                        @Html.Hidden("hid" + @dr["NSRDZDAH"] + "FUpLevelAmount", dr["FUpLevelAmount"])
                        @Html.Hidden("hid" + @dr["NSRDZDAH"] + "FLocalAmount", dr["FLocalAmount"])
                        <td class="tdClass" align="center">@dr["FNote"]
                        </td>
                    </tr>
                        }
                        else
                        {
                    <tr id="sumR">
                        <td class="tdClass" align="center" colspan="2">@dr["cz"]
                        </td>
                        <td class="tdClass" align="right" id='jeSUM'>@dr["FUpLevelAmount"]
                        </td>
                        <td class="tdClass" align="center">
                        </td>
                    </tr>
                        }
                    }
                }
            </table>
        </div>
        @Html.DevExpress().PopupControl(
    settings =>
    {
        settings.Name = "codeModalMode";
        settings.Width = 400;
        settings.Height = 350;
        settings.AllowDragging = true;
        settings.CloseAction = CloseAction.CloseButton;
        settings.EnableAnimation = false;
        settings.HeaderText = "企业增加";
        settings.Modal = true;
        settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
        settings.ShowFooter = true;
        settings.SetFooterTemplateContent(s =>
        {
            ViewContext.Writer.Write("<table align='center'><tr><td>");
            @Html.DevExpress().Button(footBtnSettings =>
            {
                footBtnSettings.Name = "btnOK";
                footBtnSettings.Text = "确定";
                footBtnSettings.ClientSideEvents.Click = "function(s,e){popContent.OK()}";
                footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/ok.png");
                footBtnSettings.CausesValidation = false;
            }).GetHtml();
            ViewContext.Writer.Write("</td><td>");
            @Html.DevExpress().Button(footBtnSettings =>
            {
                footBtnSettings.Name = "btnCancel";
                footBtnSettings.Text = "取消";
                footBtnSettings.ClientSideEvents.Click = "codeCancel";
                footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/no.png");
                footBtnSettings.CausesValidation = false;
            }).GetHtml();
            ViewContext.Writer.Write("</td></tr></table>");

        });
        settings.SetContent(() =>
        {
            ViewContext.Writer.Write("<iframe  id='popContent' name='popContent' style='width:100%;height:300px' frameborder='0' ></iframe>");
        });
    }).GetHtml()

        @Html.Hidden("hdjsAlert", (ViewData["jsAlert"]));
        @Html.Hidden("hidFUpLevelAllowanceID", (ViewData["FUpLevelAllowanceID"]));  
        @Html.Hidden("himportdata", "") ;

    }
</body>
</html>
